package com.dmall.opening.up.records.dao.mysql.mybatis.config;

import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;

import java.util.List;

public class SpringMybatisObjectFactory extends DefaultObjectFactory {

    private final AutowireCapableBeanFactory autowireFactory;

    public SpringMybatisObjectFactory(AutowireCapableBeanFactory autowireFactory) {
        this.autowireFactory = autowireFactory;
    }

    @Override
    public <T> T create(Class<T> type, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
        T object = super.create(type, constructorArgTypes, constructorArgs);
        autowireFactory.autowireBean(object);
        return object;
    }
}
